<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/5/10
 * Time: 10:42
 */
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use MyClass\Admin\ArticleClassBase;
use Illuminate\Support\Facades\Request;

class ArticleClassController extends Controller
{
  public function sClass()
  {
      session(["nowPage"=>"/user_sClass"]);
      $data=ArticleClassBase::_sClass();
      if($data)
      {
         return view("Admin.ArticleClass.sArticleClass",$data);
      }
      else
      {
          return false;
      }
  }

    /**
     * @return bool|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function uClass()
    {
        $data=Request::only("class_name","class_intro","class_id");
        $input["class_update_time"]=date("Y-m-d H:i:s");
        $input["class_name"]=$data["class_name"];
        $input["class_intro"]=$data["class_intro"];
        $a =new ArticleClassBase($data["class_id"]);
        $res=$a->uClass($input);
        if($res)
        {
            return redirect("/user_sClass");
        }
        else
        {
            return false;
        }
    }

    /**
     * @param $class_id
     * @return bool|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function dClass($class_id)
    {
        $a = new ArticleClassBase($class_id);
        $res=$a->dClass();
        if($res)
        {
            return redirect("/user_sClass");
        }
        else
        {
            return false;
        }
    }
    public function aClass()
    {
        $data=Request::only("class_name","class_intro");

        $res=ArticleClassBase::aClass($data);

        if($res)
        {
            return redirect("/user_sClass");
        }
        else
        {
            return false;
        }
    }


    public function initClass(){
        $init_data=array("概&nbsp;&nbsp;括","实验教学","实验队伍","体制与管理","设备与环境");
        for($i=0;$i<count($init_data);$i++){
            $data['class_name']=$init_data[$i];
            ArticleClassBase::aClass($data);
        }
        return redirect("/user_sClass");
    }

}